<template>
  <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">

 
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-refresh" @click="handleRest">
        刷新
      </el-button>
        
 
    <ul v-infinite-scroll="load"
      style="width: 100%;background-color: rgba(0, 0, 0, 0.10);height: 300px;overflow: auto;padding:0 8px;">
      <ul class="infinite-list" style="width: 100%; min-height: 320px;padding-top: 8px;">
        <li v-for="item in contentList" style="display: block;margin-bottom: 8px;"> {{ item }} </li>
      </ul>
    </ul>
    <div slot="footer" class="dialog-footer">

      <el-button type="primary" :loading="loading" @click="dialogFormVisible = false">
        {{ $t('table.confirm') }}
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
import { createDataExtractionTaskLog, updateDataExtractionTaskLog, getDetail } from '@/api/dataextractiontasklog/dataExtractionTaskLog'

export default {
  name: 'DataExtractionTaskLogForm',
  data() {
    return {
      rules: {
      },
      temp: {},
      textMap: {
        update: '编辑',
        create: '新建'
      },
      passobj: {
        fromLineNum: 0,
        logId: ''
      },
      contentList: [],
      loading: false,
      key: '',
      dialogFormVisible: false,
      dialogStatus: ''
    }
  },
  methods: {
    handleRest(){
      getDetail(this.passobj).then(res => {
         
        if (res.data.code == 200) {
          this.contentList = res.data.data.logContent
          this.passobj.fromLineNum=res.data.data.toLineNum+1
          this.key=res.data.data.end
          this.$message.success('刷新成功')
        }
      })
    },
    load() {
      if(!this.key){
        getDetail(this.passobj).then(res => {
         
        if (res.data.code == 200) {
          this.contentList =[...this.contentList,...res.data.data.logContent]
          this.passobj.fromLineNum=res.data.data.toLineNum+1
          this.key=res.data.data.end
        }
      })
      }else{
       
      }
     
    },
    getList() {
      this.$emit('refreshList')
    },
    resetTemp() {
      this.loading = false
      this.temp = {
        id: undefined,
              status: undefined,
              executeJobId: undefined,
              executeDate: undefined,
              executeResult: undefined,
              tenantId: undefined
            }
    },
    getData() {
      getDetail(this.passobj).then(res => {
         
        if (res.data.code == 200) {
          this.contentList = res.data.data.logContent
          this.passobj.fromLineNum=res.data.data.toLineNum+1
          this.key=res.data.data.end
        }
      })
    },
    handleUpdate(id) {
      this.resetTemp()
      this.passobj.logId = id
      this.passobj.fromLineNum=0
      this.dialogStatus = 'look'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
      this.getData()
    },
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.loading = true
          updateDataExtractionTaskLog(this.temp).then(response => {
            this.loading = false
            if (response.data.code === 0) {
              this.dialogFormVisible = false
              this.getList()
              this.$message.success(response.data.msg)
            } else {
              this.$message.error(response.data.msg)
            }
          })
        }
      })
    }
  }
}
</script>